<template>
  <div>
    <button @click="testWebSocket">测试websocket</button>
    <button @click="modifydata">改数据</button>
    <p>{{ uavdata.altitude }}</p>
  </div>
</template>

<script>
import { connectWebsocket } from "@/utils/websocket";
export default {
  name: "testData",
  data() {
    return {
      uavdata: {
        altitude: "",
        velocityX: "",
        velocityZ: "",
        isFlying: "",
        uavId: "",
        longitude: "",
        velocityY: "",
        flyTime: "",
        latitude: "",
      },
    };
  },
  methods: {
    testWebSocket() {
      connectWebsocket(
        // 测试地址
        "ws://47.100.121.5:7529/api/cloud/1",
        // 传递给后台的数据
        "openexe",
        // { openexe: 'openexe' },
        // 成功拿到后台返回的数据的回调函数
        (data) => {
          console.log("成功的回调函数, 接收到的data数据: ", data);
          this.uavdata = JSON.parse(data);
        },
        // websocket连接失败的回调函数
        (err) => {
          console.log("失败的回调函数", err);
        }
      );
    },
    modifydata() {
      this.uavdata.altitude = 100;
    },
  },
};
</script>

<style>
</style>